products = [['iphone', 6888], ['MacPro', 14800], ['小米6', 2499], ['Coffee', 31], ['Book', 60], ['Nike', 699]]
shopping_cart = []
shopping_cost = []
price = 0

while True:
    print("------shopping List------")
    for i in range(6):
        print(i+1, products[i][0], products[i][1])
    print("=" * 24)

    choice = input("Select product number,press 'q' to exit: ")
    if choice.isdigit():
        choice = int(choice)
        if choice > 0 and ( choice <= len(products) ):
            p_item = products[choice - 1]
            shopping_cart.append(p_item[0])
            shopping_cost.append(p_item[1])
            price += p_item[1]
        else:
            print('{} is an invalid product number!'.format(choice))
    elif choice == 'q':
        print("You have bought following product:")
        for cur_item in shopping_cart:
            print(cur_item)
        print("Total cost: ", price)
        break
    else:
        print("Bad input!")

# 为实现购物车功能，仅实现了打印商品列表